package com.bong.panpan.bongcharttools.custom;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by panpan on 2017/9/28.
 */

public class SpUtil {
    private static SpUtil instance;
    private SharedPreferences sp;

    public static SpUtil getInstance() {
        if (instance == null)
            instance = new SpUtil();
        return instance;
    }

    public void init(Context context) {
        sp = context.getSharedPreferences("BongChartTool", Context.MODE_PRIVATE);
    }

    public int getInt(String key, int defValue) {
        return sp.getInt(key, defValue);
    }

    public String getStrng(String key, String defValue) {
        return sp.getString(key, defValue);
    }

    public boolean getBoolean(String key, boolean defValue) {
        return sp.getBoolean(key, defValue);
    }

    public void setInt(String key, int value) {
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt(key, value);
        editor.commit();
    }

    public void setStrng(String key, String value) {
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(key, value);
        editor.commit();
    }

    public void setBoolean(String key, boolean value) {
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(key, value);
        editor.commit();
    }
}
